<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/syleForTabs.css" TYPE="text/css"
	MEDIA="screen">
<script type="text/javascript" src="js/tabber.js"></script>
<script type="text/javascript" src="js/basic.js"></script>
<script type="text/javascript">
	var editing = false;
	window.setTimeout('initLoad()', 500);
	
	function setTaContent(content) {
		document.getElementById("taContent").value = content;
	}
	//	function setTextToCopy(content) {
	//		document.getElementById("taTextToCopy").value = request.selectedText;
	//	}
	function deleteOldKeywords() {
		var table = document.getElementById("tableKeywords");
		var row_count = table.rows.length;
		for ( var i = 0; i < (row_count - 1); i++) {
			table.deleteRow(1);
		}
	}

	function setKeywords(keywords) {
		document.getElementById("error").innerHTML = "";
		document.getElementById("addKeyword").disabled = false;
		editing = false;
		var table = document.getElementById("tableKeywords");
		for ( var i = 0; i < keywords.length; i++) {
			var keyword = keywords[i];
			var row_count = table.rows.length;
			var row = table.insertRow(row_count);

			var cell1 = row.insertCell(0);
			cell1.innerHTML = "";

			var cell2 = row.insertCell(1);
			cell2.innerHTML = keyword.keyword;

			var cell3 = row.insertCell(2);
			var element = document.createElement("a");
			element.setAttribute("onclick", "editKeyword(" + row_count + ")");
			var element1 = document.createElement("img");
			element1.setAttribute("style",
					"width: 30px; height:30px; cursor:pointer;");
			element1.setAttribute("onmouseover", "'this.sytle.curstor = hand'");
			element1.setAttribute("border", "0");
			element1.setAttribute("src", "icons/edit.png");
			element.appendChild(element1);
			cell3.appendChild(element);

			var cell4 = row.insertCell(3);
			var element = document.createElement("a");
			element.setAttribute("onclick", "deleteKeyword(" + keyword.priority
					+ ")");
			var element1 = document.createElement("img");
			element1.setAttribute("style",
					"width: 30px; height:30px; cursor:pointer;");
			element1.setAttribute("onmouseover", "'this.sytle.curstor = hand'");
			element1.setAttribute("border", "0");
			element1.setAttribute("src", "icons/delete.png");
			element.appendChild(element1);
			cell4.appendChild(element);

			var cell5 = row.insertCell(4);
			if (i != 0) {
				var element = document.createElement("a");
				element.setAttribute("onclick", "moveUpKeyword('"
						+ keyword.priority + "')");
				var element1 = document.createElement("img");
				element1.setAttribute("style",
						"width: 30px; height:30px; cursor:pointer;");
				element1.setAttribute("onmouseover",
						"'this.sytle.curstor = hand'");
				element1.setAttribute("border", "0");
				element1.setAttribute("src", "icons/up.png");
				element.appendChild(element1);
				cell5.appendChild(element);

			} else
				cell5.innerHTML = "";

			var cell6 = row.insertCell(5);
			if (i != (keywords.length - 1)) {
				var element = document.createElement("a");
				element.setAttribute("onclick", "moveDownKeyword('"
						+ keyword.priority + "')");
				var element1 = document.createElement("img");
				element1.setAttribute("style",
						"width: 30px; height:30px; cursor:pointer;");
				element1.setAttribute("onmouseover",
						"'this.sytle.curstor = hand'");
				element1.setAttribute("border", "0");
				element1.setAttribute("src", "icons/down.png");
				element.appendChild(element1);
				cell6.appendChild(element);
			} else
				cell6.innerHTML = "";
		}
	}
	function setErrorMessage(error) {
		document.getElementById("error").innerHTML = error;
	}
	function areFieldsEmpty(priority, keyword) {
		if (priority == "") {
			setErrorMessage("priority's field is empty!");
			return true;
		}
		if (keyword == "") {
			setErrorMessage("keyword's field is empty!");
			return true;
		}
		return false;
	}
	function addNewKeywordHTML() {
		var priority = document.getElementById("priorityNewK").value;
		var keyword = document.getElementById("keywordNewK").value;
		if (!areFieldsEmpty(priority, keyword)) {
			try {
				addNK(priority, keyword);
				document.getElementById("priorityNewK").value = "";
				document.getElementById("keywordNewK").value = "";
			} catch (error) {
				setErrorMessage(error);
			}
		}
	}
	function saveEditedKeyword(row_index) {

		var priority = row_index;
		var keyword = document.getElementById("editedKeyword").value;
		if (!areFieldsEmpty(priority, keyword)) {
			try {
				saveEK(row_index, priority, keyword);
			} catch (error) {
				setErrorMessage(error);
			}
		}
	}

	function moveUpKeyword(priority) {
		var new_priority = (parseInt(priority) - 1).toString();
		try {
			changePriority(priority, new_priority);
		} catch (error) {
			setErrorMessage(error);
		}
	}
	function moveDownKeyword(priority) {
		var new_priority = (parseInt(priority) + 1).toString();
		try {
			changePriority(priority, new_priority);
		} catch (error) {
			setErrorMessage(error);
		}
	}

	function editKeyword(row_index) {
		if (!editing) {
			editing = true;
			var table = document.getElementById("tableKeywords");
			var row = table.rows[row_index];
			var cell1 = row.cells[1];
			var element = document.createElement("input");
			element.setAttribute("type", "text");
			element.setAttribute("value", cell1.innerHTML);
			element.setAttribute("id", "editedKeyword");
			element.setAttribute("style", "width: 210px");
			cell1.innerHTML = "";
			cell1.appendChild(element);

			var cell2 = row.cells[2];
			var element = document.createElement("a");
			element.setAttribute("onclick", "saveEditedKeyword(" + row_index
					+ ")");
			var element1 = document.createElement("img");
			element1.setAttribute("style",
					"width: 30px; height:30px; cursor:pointer;");
			element1.setAttribute("onmouseover", "'this.sytle.curstor = hand'");
			element1.setAttribute("border", "0");
			element1.setAttribute("src", "icons/save.png");
			element.appendChild(element1);
			cell2.innerHTML = "";
			cell2.appendChild(element);

			var cell3 = row.cells[3];
			var element = document.createElement("a");
			element.setAttribute("onclick", "cancelEditingKeyword()");
			var element1 = document.createElement("img");
			element1.setAttribute("style",
					"width: 30px; height:30px; cursor:pointer;");
			element1.setAttribute("onmouseover", "'this.sytle.curstor = hand'");
			element1.setAttribute("border", "0");
			element1.setAttribute("src", "icons/cancel.png");
			element.appendChild(element1);
			cell3.innerHTML = "";
			cell3.appendChild(element);
			var cell4 = row.cells[4];
			cell4.innerHTML = "";
			var cell5 = row.cells[5];
			cell5.innerHTML = "";
		}
	}
	function setLinksHTML(discoveries) {
		var table = [ document.getElementById("tableLinks"),
				document.getElementById("tableLinksDummy") ];
		for ( var j = 0; j < 2; j++) {
			for ( var i = 0; i < discoveries.length; i++) {
				var discovery = discoveries[i];
				var rowCount = table[j].rows.length;
				var row = table[j].insertRow(rowCount);

				var cell1 = row.insertCell(0);
				cell1.innerHTML = discovery.priority;

				var cell2 = row.insertCell(1);
				var element = document.createElement("a");
				element.setAttribute("onclick", "openLink('" + discovery.group
						+ "')");
				element.setAttribute("style", "cursor:pointer;");
				element.setAttribute("onmouseover",
						"'this.sytle.curstor = hand'");
				element.innerHTML = "<u><font color='blue'>" + discovery.group
						+ "</font></u>";
				cell2.appendChild(element);

				var cell3 = row.insertCell(2);
				cell3.innerHTML = discovery.link.length;
			}
		}
	}

	function deleteOldLinks() {
		var table = [ document.getElementById("tableLinks"),
				document.getElementById("tableLinksDummy") ];
		var row_count = table[0].rows.length;
		for ( var j = 0; j < 2; j++) {
			for ( var i = 0; i < (row_count - 1); i++) {
				table[j].deleteRow(1);
			}
		}
	}
	function setPendingStatus() {
		var table = [ document.getElementById("tableLinks"),
				document.getElementById("tableLinksDummy") ];
		for ( var j = 0; j < 2; j++) {
			var rowCount = table[j].rows.length;
			var row = table[j].insertRow(rowCount);
			var cell1 = row.insertCell(0);
			cell1.innerHTML = "";

			var cell2 = row.insertCell(1);
			cell2.innerHTML = "<font color=orange><i> Loading ...</i></font>";

			var cell3 = row.insertCell(2);
			cell3.innerHTML = "";
			
		}
	}
</script>
<title>Help me!</title>
</head>
<body>
<h1>Help me!</h1>
<div class="tabber">
<div class="tabbertab">
<h2>Basic</h2>
<p><br>
<b>Links to relevant content:</b> <br>
<table width="400" cellspacing="0" cellpadding="1" id="tableLinksDummy"
	style='table-layout: fixed; word-break: break-all'>
	<col width=70>
	<col width=150>
	<col width=180>
	<tbody>
		<tr>
			<td width="70">Priority</td>
			<td width="150">Group</td>
			<td width="180">No of results</td>
		</tr>
	</tbody>
</table>
<!-- 
<hr>
<INPUT type="button" value="Copy" id="copyDummy" style="width: 138px"
	onclick="copySelectedText()"> --></p>
</div>
<div class="tabbertab">
<h2>Advanced</h2>
<p>
<br>
<b>Links to relevant content:</b> <br>
<table width="400" cellspacing="0" cellpadding="1" id="tableLinks"
	style='table-layout: fixed; word-break: break-all'>
	<col width=70>
	<col width=150>
	<col width=180>
	<tbody>
		<tr>
			<td width="70">Priority</td>
			<td width="150">Group</td>
			<td width="180">No of results</td>
		</tr>
	</tbody>
</table>
<br>
<!-- <INPUT type="button" value="Refresh" id="refresh"
	onclick="loadForFirstTime()"><br> --> <a id="home"
	onclick="changeHomeToCurrentPage()" style="cursor: pointer;"
	onmouseover="this.style.cursor='hand'"> <img src="icons/home.png"
	style="width: 30px; height: 30px;"> <b>Set this as home </b> </a><br>

<br>
<b>Keywords:</b>
<div id="error" style="color: red"></div>
<br>
<table width="400" cellspacing="0" cellpadding="1" id="tableKeywords"
	style='table-layout: fixed; word-break: break-all'>
	<col width=20>
	<col width=220>
	<col width=40>
	<col width=40>
	<col width=40>
	<col width=40>
	<tbody>
		<tr>
			<td width="20"></td>
			<td width="220">Keyword</td>
			<td width="40"></td>
			<td width="40"></td>
			<td width="40"></td>
			<td width="40"></td>
		</tr>
	</tbody>
</table>
<br>
<table width="400" cellspacing="0" cellpadding="1"
	style='table-layout: fixed; word-break: break-all'>
	<col width=70>
	<col width=190>
	<col width=140>
	<tbody>
		<tr>
			<td><INPUT type="text" style="width: 68px" value="priority"
				id="priorityNewK"></td>
			<td><INPUT type="text" style="width: 188px" value="keyword"
				id="keywordNewK"></td>
			<td align="center"><a id="addKeyword"
				onclick="addNewKeywordHTML()" disabled="true"> <img border="0"
				src="icons/add.png" style="width: 30px; height: 30px"> </a> <!-- <INPUT type="button" value="Add"
			id="addKeyword" style="width: 138px" onclick="addNewKeywordHTML()"
			disabled="true"> --></td>
		</tr>
	</tbody>
</table>
<br>
<b>Content: </b><br>
<textarea style="width: 400px" rows="3" id="taContent"></textarea> <br>
<!--
<hr>
<INPUT type="button" value="Copy" id="copy" style="width: 138px"
	onclick="copySelectedText()">
 <textarea style="width: 400px"
	rows="3" id="taTextToCopy"></textarea> --></p>
</div>
</div>
</body>
</html>
